package com.example.lx6_8

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.aa.mvvm.BaseViewActivity
import com.example.lx6_8.databinding.ActivityMain2Binding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
import java.util.Timer
import kotlin.concurrent.timerTask

@AndroidEntryPoint
class MainActivity2 : BaseViewActivity<ActivityMain2Binding>() {

    var timer = Timer()
    var num = System.currentTimeMillis()
    val sdf = SimpleDateFormat("HH:mm:ss")
    var type = 1
    override fun initView() {
        binding.iv.setOnClickListener {
            ARouter.getInstance().build("/app/MainActivity").navigation()
        }
        binding.conLocation.setOnClickListener {
            ARouter.getInstance().build("/app/MainActivity3").navigation()
        }

        timer = Timer()
        lifecycleScope.launch(Dispatchers.IO){
            timer.schedule(timerTask {
                num = System.currentTimeMillis()
                lifecycleScope.launch(Dispatchers.Main){
                    binding.signTime.text = sdf.format(num) + ""
                }
            },0,1000)
        }

        binding.btnSign.setOnClickListener {
            if(type == 1){
                binding.tv1.text = "签到时间："+sdf.format(System.currentTimeMillis())
            }else if(type == 2){
                binding.tv2.text = "签退时间："+sdf.format(System.currentTimeMillis())
                binding.btnSign.isEnabled = false
            }
            type++
        }

    }

    override fun initData() {

    }

}